<?php

class FileSystemConnector extends Singleton {
	private static $fs;

	/**
	 * Enables singleton working properly
	 *
	 * @see singleton.php
	 */
	public static function instance()
	{
		return self::getInstanceOf( get_class() );
	}

	public static function get( $args = false ) {
		$method = FileSystemTools::get_filesystem_method();

		if ( ! $method )
			return false;

		$abstraction_file = MP_PATH . '/mp-includes/classes/filesystem_'.$method.'.php';
		if( ! file_exists($abstraction_file) )
			return;

		require_once($abstraction_file);
		$method = "FileSystem_$method";

		$this->fs = new $method($args);

		if ( $this->fs->errors->get_error_code() )
			return false;

		if ( !$this->fs->connect() )
			return false; //There was an error connecting to the server.

		return $this->fs;
	}
}